package belf.migrate.api.util;

import belf.migrate.api.common.DatabaseIdentifier;
import belf.migrate.api.type.DbObjectType;

import java.util.List;

public enum VerifyObjectTypes {
    ORACLE_DAMENG(DatabaseIdentifier.ORACLE, DatabaseIdentifier.DAMENG,
            List.of(
                    DbObjectType.TABLE,
                    DbObjectType.VIEW,
                    DbObjectType.SEQUENCE,
                    DbObjectType.PROCEDURE,
                    DbObjectType.FUNCTION,
                    DbObjectType.TYPE,
                    DbObjectType.TRIGGER)),
    MYSQL_DAMENG(DatabaseIdentifier.MYSQL, DatabaseIdentifier.DAMENG,
            List.of(
                    DbObjectType.TABLE,
                    DbObjectType.VIEW,
                    DbObjectType.PROCEDURE,
                    DbObjectType.FUNCTION,
                    DbObjectType.TRIGGER)),
    ORACLE_KINGBASE(DatabaseIdentifier.ORACLE, DatabaseIdentifier.KINGBASE,
            List.of(
                    DbObjectType.TABLE,
                    DbObjectType.VIEW,
                    DbObjectType.SEQUENCE,
                    DbObjectType.PROCEDURE,
                    DbObjectType.FUNCTION,
                    DbObjectType.TYPE,
                    DbObjectType.TRIGGER)),
    MYSQL_KINGBASE(DatabaseIdentifier.MYSQL, DatabaseIdentifier.KINGBASE,
            List.of(
                    DbObjectType.TABLE,
                    DbObjectType.VIEW,
                    DbObjectType.PROCEDURE,
                    DbObjectType.FUNCTION,
                    DbObjectType.TRIGGER)),
    ;

    private String sourceCatalog;

    private String sinkCatalog;

    private List<DbObjectType> objectTypes;

    VerifyObjectTypes(String sourceCatalog, String sinkCatalog, List<DbObjectType> objectTypes) {
        this.sourceCatalog = sourceCatalog;
        this.sinkCatalog = sinkCatalog;
        this.objectTypes = objectTypes;
    }

    public static boolean isSupport(String sourceCatalog, String sinkCatalog, DbObjectType objectType) {
        for (VerifyObjectTypes verifyObjectTypes : VerifyObjectTypes.values()) {
            if (verifyObjectTypes.sourceCatalog.equals(sourceCatalog) && verifyObjectTypes.sinkCatalog.equals(sinkCatalog) && verifyObjectTypes.objectTypes.contains(objectType)) {
                return true;
            }
        }
        return false;
    }

    public static int getObjectTypeSize(String sourceCatalog, String sinkCatalog) {
        for (VerifyObjectTypes verifyObjectTypes : VerifyObjectTypes.values()) {
            if (verifyObjectTypes.sourceCatalog.equals(sourceCatalog) && verifyObjectTypes.sinkCatalog.equals(sinkCatalog)) {
                return verifyObjectTypes.getObjectTypes().size();
            }
        }
        return 0;
    }

    public String getSourceCatalog() {
        return sourceCatalog;
    }

    public void setSourceCatalog(String sourceCatalog) {
        this.sourceCatalog = sourceCatalog;
    }

    public String getSinkCatalog() {
        return sinkCatalog;
    }

    public void setSinkCatalog(String sinkCatalog) {
        this.sinkCatalog = sinkCatalog;
    }

    public List<DbObjectType> getObjectTypes() {
        return objectTypes;
    }

    public void setObjectTypes(List<DbObjectType> objectTypes) {
        this.objectTypes = objectTypes;
    }
}
